package com.nuotu.datawall.clouddata.adapter;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nuotu.datawall.clouddata.R;
import com.nuotu.datawall.clouddata.been.BasicData;

import java.util.ArrayList;

public class Grid_jcsj_adapter  extends ArrayAdapter {

    private Context mContext;
    private int layoutResourceId;
    private ArrayList<BasicData> mGridData = new ArrayList<BasicData>();


    public Grid_jcsj_adapter(Context context, int resource, ArrayList<BasicData> objects) {
        super(context, resource, objects);
        this.mContext = context;
        this.layoutResourceId = resource;
        this.mGridData = objects;
    }

    public void setGridData(ArrayList<BasicData> mGridData) {
        this.mGridData = mGridData;
        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;

        if (convertView == null) {
            LayoutInflater inflater = ((Activity)mContext).getLayoutInflater();
            convertView = inflater.inflate(layoutResourceId, parent, false);
            holder = new ViewHolder();
            holder.tv_jscj_item_title = (TextView) convertView.findViewById(R.id.tv_jscj_item_title);
            holder.tv_jscj_item_data = (TextView) convertView.findViewById(R.id.tv_jscj_item_data);
            holder.iv_jscj_item_image = (ImageView) convertView.findViewById(R.id.iv_jscj_item_image);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        BasicData item = mGridData.get(position);
        holder.tv_jscj_item_title.setText(item.getTitle());
        holder.tv_jscj_item_data.setText(item.getData());
        if(position==(mGridData.size()-1)){
            holder.iv_jscj_item_image.setVisibility(View.GONE);
        }
        return convertView;
    }
    private class ViewHolder {
        TextView tv_jscj_item_title;
        TextView tv_jscj_item_data;
        ImageView iv_jscj_item_image;
    }

}
